﻿Namespace PL.MESSDK
    Public Class Site_PL
        Inherits PLBase
        Implements IPLProcess



        Private Shared _defaultSiteRow As DataRow

        Public Shared Property DefaultSite As DataRow
            Get
                If _defaultSiteRow Is Nothing Then
                    _defaultSiteRow = GetDefaultSite()
                End If
                Return _defaultSiteRow
            End Get
            Set(value As DataRow)
                _defaultSiteRow = value
            End Set
        End Property

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(ByVal queryName As String)
            MyBase.New(queryName)
        End Sub

        Sub OnRowUpdating(ByVal sender As Object, ByVal e As SqlRowUpdatingEventArgs) Handles MetaDataTable.OnRowUpdating
        End Sub

        Public Overrides Function Delete() As Boolean
            'Throw New NotImplementedException("Delete To Come...")
            Return False
        End Function

        Public Overrides Function Validate() As Boolean
            'Throw New NotImplementedException("Validate To Come...")
            Return True
        End Function

        Public Function BatchRecords(dataRow() As DataRow) As Boolean Implements IPLProcess.BatchRecords
            Return True
        End Function

        Public Function CurrentRecord(dataRow As DataRow) As Boolean Implements IPLProcess.CurrentRecord
            Return True
        End Function

        Public Function NewRecord(dataRow As DataRow) As Boolean Implements IPLProcess.NewRecord
            If Me.ID IsNot Nothing Then
                dataRow("SiteID") = ID
            End If

            Return True
        End Function


        Public Shared Function GetDefaultSite() As DataRow
            Dim aRow As DataRow = Nothing
            Using site As MetaQuery = MetaQuery.GetMetaQueryByName("Site")
                site.SQLWhere = String.Format("DefaultRecord = '{0}'", 1) 'DefaultRecord = True
                site.FillResultQuery()
                If site.ResultQuery.Rows.Count > 0 Then
                    aRow = site.ResultQuery.Rows(0)
                End If
                Return aRow
            End Using
        End Function

        Public Shared Function GetSiteByID(ByVal siteID As Guid) As DataRow
            Dim aRow As DataRow = Nothing
            Using site As MetaQuery = MetaQuery.GetMetaQueryByName("Site")
                site.SQLWhere = String.Format("SiteID = '{0}'", siteID.ToString)
                site.FillResultQuery()
                If site.ResultQuery.Rows.Count > 0 Then
                    aRow = site.ResultQuery.Rows(0)
                End If
                Return aRow
            End Using
        End Function


    End Class
End Namespace
